import 'package:ac/common/ac_pv_manager.dart';
import 'package:ac/page/ac_main/ac_main_view.dart';
import 'package:ac/page/ac_me/ac_me_view.dart';
import 'package:ac/page/ac_message/ac_message_view.dart';
import 'package:ac/page/ac_video/ac_video_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'ac_home_logic.dart';

class AcHomePage extends StatelessWidget {
  final logic = Get.find<AcHomeLogic>();
  final state = Get.find<AcHomeLogic>().state;

  AcHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Obx(() {
        return IndexedStack(
          index: state.currentIndex.value,
          children: [
            AcMainPage(),
            AcVideoPage(),
            AcMessagePage(),
            AcMePage(),
          ],
        );
      }),
      bottomNavigationBar: Obx(() => Container(
            height: 50.h + ScreenUtil().bottomBarHeight,
            decoration: BoxDecoration(
              color: state.currentIndex.value == 1
                  ? const Color(0xff383636)
                  : Colors.white,
              boxShadow: const [
                BoxShadow(
                  color: Color(0x0D000000),
                  offset: Offset(0, -1),
                  blurRadius: 5,
                  spreadRadius: 2,
                ),
              ],
            ),
            child: SafeArea(
              child: Row(
                children: [
                  _bottomTab(0, "home"),
                  _bottomTab(1, "video"),
                  _bottomTab(2, "message"),
                  _bottomTab(3, "me"),
                ],
              ),
            ),
          )),
    );
  }

  Widget _bottomTab(int index, String icon) {
    return Expanded(
      child: GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () {
          state.currentIndex.value = index;
          var tabName = "";
          switch (index) {
            case 0:
              tabName = "Home";
              break;
            case 1:
              tabName = "Video";
              break;
            case 2:
              tabName = "Message";
              break;
            case 3:
              tabName = "Me";
              break;
          }
          LogPvManger.stat(page: "Tab${tabName}Page");

        },
        child: Padding(
          padding: EdgeInsets.symmetric(vertical: 12.h),
          child: Image.asset(
            "images/icon_${icon}_${state.currentIndex.value == index ? "yes" : "no"}.png",
            width: 24.w,
            height: 24.w,
          ),
        ),
      ),
    );
  }
}
